import 'package:bubbles/app/main/main_app.dart';
import 'package:bubbles/app/main/main_binding.dart';
import 'package:bubbles/http/api/api_service.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'http/api/http_config.dart';
import 'http/dio_client.dart';
import 'router/app_routes.dart';
import 'router/router_observer.dart';
import 'theme/color_palettes.dart';
import 'utils/default_refresh_indicator.dart';
import 'utils/injection.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // 强制使用软件渲染
  debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
  await Injection().init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: const Size(750, 1334),
        builder: (context, child) => _defaultRefreshConfiguration(
              GetMaterialApp(
                showPerformanceOverlay: false,
                initialRoute: AppRoutes.initial,
                getPages: AppRoutes.routes,
                navigatorObservers: [AppRouterObserver()],
                defaultTransition: Transition.rightToLeft,
                transitionDuration: const Duration(milliseconds: 150),
                title: "bubbles",
                home: const MainApp(),
                initialBinding: MainBinding(),
                locale: const Locale('zh'),
              ),
            ));
  }

  RefreshConfiguration _defaultRefreshConfiguration(Widget child) {
    return RefreshConfiguration(
        headerBuilder: () => DefaultRefreshHeader(),
        footerBuilder: () => DefaultRefreshFooter(),
        headerTriggerDistance: 180.w,
        maxOverScrollExtent: 100.w,
        maxUnderScrollExtent: 0,
        enableScrollWhenRefreshCompleted: true,
        enableLoadingWhenFailed: true,
        hideFooterWhenNotFull: false,
        enableBallisticLoad: true,
        footerTriggerDistance: 140.w,
        child: child);
  }
}
